<template>
  <div class="accidentDistribution-root">
    <formTitleVue
      title="报警趋势统计"
      :selectOptions="selectOptions"
    />
    <!-- <div id="echarts-accidentDistribution"></div> -->
    <myLine domId="alarmAnalysis-alarmTrend-echarts" height="30vh" :chartsData="chartsData" :myOption="echartsOption"/>
  </div>
</template>

<script>
  import formTitleVue from "@/components/FormTitle/formTitle.vue";
  import myLine from '@/components/Echarts/myLine.vue';
  import { time_select_optios } from '@/utils/global.js';
  import {alarmHandlingTrend} from '@/api/alarm/statistics'

  export default {
    name: "accidentDistribution",
    components: {
      formTitleVue,myLine,
    },
    props: {
      alarmTypeOptions: {
        type: Array,
        default: [],
      },
      dateValueMap:{
        type: Object,
        default: {},
      },
      dataSelectOptions:{
        type: Array,
        default: [],
      }
    },
    data() {
      return {
        selectOptions: [
          {
            selectValue: "全部类型",
            options:this.alarmTypeOptions,
            changeFn:this.changeType
          },
          {
            selectValue: 1,
            options:this.dataSelectOptions,
            changeFn:this.changeDate
          },
        ],
        chartsData: {
          xData: [],
          yData: [],
        },
        echartsOption:{
          legend:{
            show:false,
          }
        },
        searChForm: {
          startTime: '',
          endTime: '',
          dateType:'',
          modeType:""
        },
      };
    },
    methods: {
      changeType(val){
        console.log("changeType：",val)
        this.searChForm.modeType = val
        this.getData()
      },
      changeDate(item){
        console.log("changeDate：",item)
        this.searChForm.startTime = this.dateValueMap[item].startTime + " 00:00:00"
        this.searChForm.endTime = this.dateValueMap[item].endTime+ " 23:59:59"
        this.getData()
      },
      getData() {
        // console.log(this.searChForm)
        this.searChForm.dateType='02'
        alarmHandlingTrend(this.searChForm).then(res=>{
          if(res.code==200){
            this.chartsData.xData = res.data.xAxle
            this.chartsData.yData = res.data.data
          }
        })
      },
    },
    mounted() {
      this.changeDate(1)
    },
  };
</script>

<style lang="scss" scoped>
  .accidentDistribution-root {
    #echarts-accidentDistribution {
      height: 30vh;
    }
  }
</style>
